//
//  FTSmartAccountTool.m
//  FotileStyle
//
//  Created by NB1539 on 2017/9/8.
//  Copyright © 2017年 Fotile. All rights reserved.
//
// 账号的存储路径
#define FTAccountPath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"account.data"]

#import "FTSmartAccountTool.h"
#import "FTSmartAccount.h"

@implementation FTSmartAccountTool

+ (void)saveAccount:(FTSmartAccount *)account {
    // 自定义对象的存储必须用NSKeyedArchiver
    [NSKeyedArchiver archiveRootObject:account toFile:FTAccountPath];
}
+ (FTSmartAccount *)account {
    // 加载模型
    FTSmartAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:FTAccountPath];
    NSLog(@"FTAccountPath:%@",FTAccountPath);
    /* 验证账号是否过期 */
    
    // 如果expiresTime <= now，过期
    /**
     NSOrderedAscending = -1L, 升序，右边 > 左边
     NSOrderedSame, 一样
     NSOrderedDescending 降序，右边 < 左边
     */
    // 获得当前时间
    NSDate *now = [NSDate date];
    NSComparisonResult result = [account.expireDate compare:now];
    if (result != NSOrderedDescending) { // 过期
        return nil;
    }
    return account;
}

@end
